<html class="popupwin">
<!-- 
/***************************************************************
*  Copyright notice
*
*  (c) 2004 Cau guanabara <caugb@ibest.com.br>
*  (c) 2005-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This script is a modified version of a script published under the htmlArea License.
*  A copy of the htmlArea License may be found in the textfile HTMLAREA_LICENSE.txt.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
 * Quick Tag Editor Plugin for TYPO3 htmlArea RTE
 *
 * TYPO3 SVN ID: $Id: quicktag.html 2975 2008-01-29 23:01:39Z stan $
 */
-->
<head>
	<title>Quick Tag Editor</title>
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<script type="text/javascript" src="../tag-lib.js"></script>
	<script type="text/javascript">
		/*<![CDATA[*/
		<!--
		var dialog = window.opener.HTMLArea.Dialog.QuickTag;
		var curTag = "none";
		var curTagOpt = false;
		var CSSEdit = false;
		
		function Init() {
			dialog.initialize();
			
			createDropdown("tags");
			var to = document.getElementById('tagopen');
			HTMLArea._addEvent(to, "keypress", function(ev) { if (typeof choice_dropdown != "undefined") choice_dropdown(HTMLArea.is_ie ? window.event : ev); });
			
			document.getElementById('bt_colors').style.display = "none";
			document.body.onkeypress = onKeyPress;
			to.focus();
		};

		function onCancel() {
			dialog.close();
			return false;
		};

		function quoteTest(val) {
			var er = /^\w+\s*([a-zA-Z_0-9:;]+=\"[^\"]*\"\s*|[a-zA-Z_0-9:;]+=\'[^\']*\'\s*)*$/;
			return er.test(val);
		};

		function onOK() {
			var el = document.getElementById('tagopen');
			if(!el.value) {
				alert(dialog.plugin.localize("Enter the TAG you want to insert"));
				el.focus();
				return false;
			}
			if(!quoteTest(el.value)) {
				if(!quoteTest(el.value + '"')) {
					alert(dialog.plugin.localize("There are some unclosed quote"));
					el.focus();
					el.select();
					return false;
				} else {
					el.value += '"';
				}
			}

			var param = {};
			var cleanTO = document.getElementById('tagopen').value.replace(/(<|>)/g,"");
			param.tagopen = "<"+cleanTO+">";
			param.tagclose = param.tagopen.replace(/^<(\w+) ?.*>/,"</$1>"); 

			var subtag = subTagLib[curTag];
			if(typeof subtag == 'object') {
				param.tagopen = param.tagopen+subtag.op;
				param.tagclose = subtag.cl+param.tagclose;
			}

			dialog.performAction(param);
			dialog.close();
			return false;
		};

		function onKeyPress(ev) {
			if(!ev) var ev = window.event;
			switch(ev.keyCode) {
				case 13: 
					document.getElementById('bt_ok').click();
					break;
				case 27:
					dialog.close();
					return false;
			}
			return true;
		};
		
		function selchange() {
			var toadd = document.getElementById('selectag').value; 
			var oldval = document.getElementById('tagopen').value; 
			var text = (oldval+toadd).replace(/^\s*(.+)\s*$/,"$1");
			var atrib = /(\w+)=\"$/.test(toadd) ? toadd.replace(/(\w+)=\"$/, "$1") : null;
			var showcolors = (/color\: ?$/.test(toadd)) ? true : false;
			var noCSSclasses = false;
			var obj = null;
			curTag = text.replace(/(^\w+) ?.*$/, "$1");
			curTagOpt = (tagLib[curTag] == true);
			
			if (atrib) {
				var atrer = eval('/'+atrib+'=/ig');
				if(atrer.test(oldval) && !(/[^=]\"$/.test(toadd))) {
					alert(dialog.plugin.localize("This attribute already exists in the TAG"));
					return false;
				}
				switch(atrib) {
					case 'style':
						CSSEdit = true;
						break;
					case 'class':
						if(captureClasses() == 0) noCSSclasses = true;
						break;
					case 'color':
					case 'bgcolor':
					case 'bordercolor':
					case 'bordercolorlight':
					case 'bordercolordark':
						showcolors = true;
						break;
				}
				
				if(curTagOpt == true) {
					obj = eval('opAtt_'+curTag.replace(/^h[1-6]$/,"h")+'["'+atrib+'"]');
				} else {
					obj = opAtt_all[atrib];
				} 
			} else if (!CSSEdit && (/(^\w+$|\"$)/.test(toadd))) {
				obj = 'all';
				if (curTagOpt == true) obj = curTag;
				toadd += ' ';
			}
				
			if (CSSEdit && quoteTest(text)) CSSEdit = false;
				
			if (showcolors) document.getElementById('bt_colors').style.display = '';
				
			if(obj) {
				createDropdown(obj, curTag);
			} else if(!CSSEdit) {
				document.getElementById('showselect').style.visibility = 'hidden';
			}
			
			if(noCSSclasses) {
				document.getElementById('showselect').innerHTML = dialog.plugin.localize("No CSS class avaiable");
				document.getElementById('showselect').style.visibility = 'visible';
			}
			
			addchanges();
			
			function addchanges() {
				document.getElementById('tagopen').focus();
				document.getElementById('tagopen').value += toadd;
			};
		};

		function captureClasses() {
			var cont = 0;
				// If there is no '<HTML>' in the HTMLArea content, when using styleSheets[..].rule, IE generates an error.   
				// In this case, we lost the classes in external CSS files.
				// If FullPage is loaded, there is no problem.
			if(!(/<\s*html\s*>/i.test(dialog.plugin.editor.getHTML())) && document.all) {
				var styles = dialog.plugin.editor._doc.getElementsByTagName("style");
				for(var i in styles) {
					var cont = styles[i].innerHTML;
					if(typeof cont != 'undefined') {
						var cls = cont.match(/\.\w+/ig,"");
						for(var j in cls) if(/^\.\w+$/.test(cls[j])) {
							var classname = cls[j].replace(/\./,"")+'"';
							opAtt_all['class'][cls[j]] = classname;
							cont++;
						}
					}
				}
				return cont;
			}

			var styleSheet = null;
			var styles = dialog.plugin.editor._doc.styleSheets;
			for (var i = 0; i < styles.length; i++) {
				styleSheet = styles[i];
				if(document.all) {
					var _rules = styleSheet.rules;
				} else {
					var _rules = styleSheet.cssRules;
				}
				for (var j = 0; j < _rules.length; j++) {
					var rule = _rules[j];
					if(/^\.\w+$/.test(rule.selectorText)) {
						var classname = rule.selectorText.replace(/\./,"")+'"';
						opAtt_all['class'][rule.selectorText] = classname;
						cont++;
					}
				}
			}
			return cont;
		};

		function choice_dropdown(e) {
			if (document.all) var Key = e.keyCode;
				else var Key = e.charCode;
			if (Key != 32) return;

			var text = document.getElementById('tagopen').value.replace(/^\s*([^\s]+)\s*$/,"$1");
			if (CSSEdit && quoteTest(text)) CSSEdit = false;
			if (CSSEdit) return;

			if (curTag == 'none') {
				curTag = text.replace(/(^\w+) ?.*$/, "$1");
				curTagOpt = tagLib[curTag];
			}

			if(!/\w/.test(text)) {
				document.getElementById('tagopen').value = ''; 
				createDropdown("tags");
				return;
			}

			var att = 'all';
			if (curTagOpt == true) att = curTag;
			createDropdown(att, curTag);
		};
		
		function createDropdown(type,tag) {
			var _div = document.getElementById('showselect');
			while(_div.hasChildNodes()) _div.removeChild(_div.firstChild);
			_div.style.visibility = 'visible';
			
			var _sel = document.createElement("select");
			_sel.id = "selectag";
			_sel.onchange = function() { selchange(); };
			
			if (typeof(type) == 'object') {
				var obj = type;
				forObj(dialog.plugin.localize("OPTIONS"),'options');
				_div.appendChild(_sel);
				return;
			}
			
			if (type == 'tags') {
				var obj = new Object();
				if (dialog.plugin.denyTags) {
					var denyTags = dialog.plugin.denyTags.split(",").join("|").replace(/ /g, "");
					var expr = new RegExp("^("+denyTags+")$");
					for (var i in allTags) {
						if (!expr.test(i)) obj[i] = allTags[i];
					}
				} else {
					obj = allTags;
				}
				forObj(dialog.plugin.localize("TAGs"),'tags');
				_div.appendChild(_sel);
				return;
			}
			
			var topt = eval('opTag_'+type.replace(/^h[1-6]$/,"h"));
			if (typeof(topt) == 'object') {
				var obj = new Object();
				var allowedAttribs = "";
				if (typeof(tag) == "string" && (dialog.plugin.allowedAttribs || (dialog.plugin.tags && dialog.plugin.tags[tag] && dialog.plugin.tags[tag]["allowedAttribs"]))) {
					if (dialog.plugin.allowedAttribs) {
						allowedAttribs = dialog.plugin.allowedAttribs.split(",").join("|").replace(/ /g, "");
					}
					if (dialog.plugin.tags && dialog.plugin.tags[tag] && dialog.plugin.tags[tag]["allowedAttribs"]) {
						if (allowedAttribs) allowedAttribs =  allowedAttribs + "|";
						allowedAttribs += dialog.plugin.tags[tag]["allowedAttribs"].split(",").join("|").replace(/ /g, "");
					}
					var expr = new RegExp("^("+allowedAttribs+")$");
					for (var i in topt) {
						if (expr.test(i)) obj[i] = topt[i];
					}
				} else {
					obj = topt;
				}
			} else {
				return;
			}
			forObj(dialog.plugin.localize("ATTRIBUTES"),'attributes');
			_div.appendChild(_sel);

			function forObj(first,type) {
				if (first) {
					var opt = document.createElement("option");
					opt.appendChild(document.createTextNode(first));
					_sel.appendChild(opt);
				}
				for (var i in obj) {
					var opt = document.createElement("option");
					opt.appendChild(document.createTextNode(i));
					opt.value = obj[i];
					_sel.appendChild(opt);
				}
			};
		};
			// Called from the TYPO3 Color plugin
		var SelectColorDialog = new Object();
		SelectColorDialog.insertColor = function (val) {
			insertColor(val);
		};
			// Called from the Default Color plugin
		function insertColor(val) {
			if(val && val != null) {
				if(CSSEdit) {
					val += "; ";
				} else {
					val += '" ';
				}
				document.getElementById('tagopen').value += val;
				document.getElementById('bt_colors').style.display = "none";
				document.getElementById('tagopen').focus();
				var att = 'all';
				if (curTagOpt == true) att = curTag;
				createDropdown(att, curTag);
			}
		};
		function colors() {
			var colorPlugin = dialog.plugin.editor.plugins.TYPO3Color;
			if (colorPlugin) {
				colorPlugin = colorPlugin.instance;
				colorPlugin.dialogSelectColor("tag", "", SelectColorDialog, window);
			} else {
				colorPlugin = dialog.plugin.editor.plugins.DefaultColor;
				if (colorPlugin) {
					colorPlugin.instance.onButtonPress(dialog.plugin.editor, "QuickTag");
				}
			}
		};
		// -->
		/*]]>*/
	</script>
</head>
<body class="popupwin" onload="Init();">
<div class="title">Quick Tag Editor</div>
<form action="" method="get">
	<div style="text-align: center; padding: 3px; background-color: #e9e9e9;"> 
		<strong style="font-size: 14px;">&lt;</strong>
		<input id="tagopen" type="text" style="background-color: #e9e9e9; width: 370px; border-width: 0px;" />
		<strong style="font-size: 14px;">&gt;</strong>
	</div>
	<div class="space"></div>
	<div id="showselect" style="position: absolute; left: 7px; top: 81px; width: 150px; z-index: 100; visibility: visible; height: 13px; color: red;"></div>
	<div class="buttons">
		<button type="button" id="bt_colors" onclick="colors();">Colors</button> 
		<button type="button" id="bt_ok" onclick="return onOK();">Ok</button>
		<button type="button" onclick="return onCancel();">Cancel</button>
	</div>
</form>
</body>
</html>
